from django.shortcuts import render
from notice.models import Notice
from information.models import Information

# Create your views here.
def get_index(request):
    notices_5 = Notice.objects.all().order_by('-update_time')[1:6]

    if len(Notice.objects.all()) > 0:
        top_1_notice = Notice.objects.all().order_by('-update_time')[0]
    else:
        top_1_notice = {
            'title': '暂无通知',
            'content': '暂无通知'
        }

    if len(top_1_notice.content) > 240:
        top_1_notice.content = top_1_notice.content[:240]

    intro = Information.objects.get(type='简介')

    return render(request, 'index/index.html', {
        'notices_5': notices_5,
        'top_1_notice': top_1_notice,
        'intro': intro.content[:240]
    })
